/*
 * Copyright (c) 2006 - 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.*;

/**
 * <p>Project: app2022 - List4
 * <p>Powered by webrx On 2022-01-14 16:37:11
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class List4 {

    public static void main(String[] args) {
        List<User> list = new ArrayList<>(List.of(new User(11,"李四",18),new User(19,"周强强",68),new User(12,"张三",25),new User(13,"张三丰",22),new User(14,"赵四",38)));
        System.out.println(list);
        //乱序
        Collections.shuffle(list);
        System.out.println(list);
        //根据年龄降序
        Collections.sort(list,(a,b)->b.getAge()-a.getAge());
        System.out.println(list);

        //根据年龄升序
        Collections.sort(list,(a,b)->a.getAge()-b.getAge());
        System.out.println(list);
    }

    public static void test(String[] args) {
        List<Integer> list = new ArrayList<>(List.of(10,5,20,6,3,100,200,9));
        System.out.println(list);
        //乱序
        Collections.shuffle(list);
        System.out.println(list);

        //升序
        Collections.sort(list);
        System.out.println(list);

        //升序
        Collections.sort(list,(a,b)->a-b);
        System.out.println(list);

        //降序
        Collections.sort(list,(a,b)->b-a);
        System.out.println(list);


        //字符串List<String> 排序
        List<String> ls = new ArrayList<>(List.of("javascript","c","go","ruby","java","php","python"));
        System.out.println(ls);
        Collections.shuffle(ls);//乱序 洗牌
        System.out.println(ls);
        Collections.sort(ls);//升序
        System.out.println(ls);
        Collections.sort(ls, Comparator.reverseOrder());//降序
        System.out.println(ls);

        //字符串根据长度升序
        Collections.sort(ls,(a,b)->a.length()-b.length());
        System.out.println(ls);
        //字符串根据长度降序
        Collections.sort(ls,(x,y)->y.length()-x.length());
        System.out.println(ls);


    }
}
